from utils.import_utils import *
from dao.user_dao import *

"""
功能:从excel导入信息
返回:创建失败的姓名列表
"""


def import_users_from_excels(file_name: str) -> {int, list, int}:
    name_data = get_excels_data(file_name)
    failed = []
    count = 0
    total = len(name_data)
    for user in name_data:
        name = user[0]
        password = user[1]
        if len(search_user_info_by_name(name)) == 0:
            insert_user_info(User(name, password))
            count += 1
        else:
            failed.append(name)
    return {"total": total, "failed": failed, "success": count}


if __name__ == '__main__':
    pass
